package com.starblink.post.detail.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.starblink.android.basic.util.ImageUtils;
import com.starblink.android.basic.widget.CustomRadiusImageView;
import com.starblink.post.R;
import com.starblink.rocketreserver.fragment.PostD;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

/**
 * 自定义布局，下面是常见的图片样式，更多实现可以看demo，可以自己随意发挥
 */

public class PostImageAdapter extends BannerAdapter<PostD.Picture, PostImageAdapter.BannerViewHolder> {
    public interface CallBack {
        void click(PostD.Picture url);
    }

    public interface GuideCallBack {
        void show(String url, ImageView iv);
    }

    Context context;

    CallBack callBack;
    GuideCallBack guideCallBack;

    public PostImageAdapter(List<PostD.Picture> mDatas, Context context, CallBack callBack, GuideCallBack guideCallBack) {
        //设置数据，也可以调用banner提供的方法,或者自己在adapter中实现
        super(mDatas);
        this.context = context;
        this.callBack = callBack;
        this.guideCallBack = guideCallBack;
    }

    //创建ViewHolder，可以用viewType这个字段来区分不同的ViewHolder
    @Override
    public BannerViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_image_banner, parent, false);
        return new BannerViewHolder(view);
    }

    @Override
    public void onBindView(BannerViewHolder holder, PostD.Picture data, int position, int size) {
        ImageUtils.loadImage(context, data.getPictureF().getPicUrl(), holder.img);
//        boolean imageIdentifyFlag = data.getPictureF().getImageIdentifyFlag();
//        if (imageIdentifyFlag) {
//            guideCallBack.show(data.getPictureF().getPicUrl(), holder.imgSearch);//展示引导
//            holder.imgSearch.setVisibility(View.VISIBLE);
//            holder.imgSearch.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    callBack.click(data);
//                }
//            });
//        } else {
//            holder.imgSearch.setVisibility(View.GONE);
//        }
    }

    class BannerViewHolder extends RecyclerView.ViewHolder {
        RelativeLayout rlContent;
        CustomRadiusImageView img;
        ImageView imgSearch;

        public BannerViewHolder(@NonNull View view) {
            super(view);
            this.img = view.findViewById(R.id.iv);
            this.imgSearch = view.findViewById(R.id.iv_search);
            this.rlContent = view.findViewById(R.id.rl_content);
        }
    }
}

